package cn.kgc.maoqichao.microservicecloudproviderdept8001.service;

import cn.kgc.maoqichao.microservicecloudproviderdept8001.mapper.WorkorderMapper;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.Workorder;
import cn.kgc.maoqichao.microservicecloudproviderdept8001.pojo.WorkorderExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WorkorderServiceImpI implements WorkorderService{
    @Resource
    WorkorderMapper workorderMapper;
    @Override
    public List<Workorder> getAll(List<Integer> workIdList) {
        WorkorderExample example = new WorkorderExample();
        example.createCriteria().andIdIn(workIdList);
        return workorderMapper.selectByExample(example);
    }

    @Override
    public PageInfo<Workorder> queryWorkAll(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        WorkorderExample example = new WorkorderExample();
        example.createCriteria().andExecutorLike('%'+keyword+'%');
        List<Workorder> list = workorderMapper.selectByExample(example);
        return new PageInfo<>(list);
    }

    @Override
    public void saveWork(Workorder workorder) {
        workorderMapper.insert(workorder);
    }

    @Override
    public void updateWork(Workorder workorder) {
        workorderMapper.updateByPrimaryKey(workorder);
    }

    @Override
    public void deleteWork(List<Integer> workIdList) {
        WorkorderExample example = new WorkorderExample();
        example.createCriteria().andIdIn(workIdList);
        workorderMapper.deleteByExample(example);
    }
}
